from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-03-11 14:02:32.901734
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Fri, 11, Mar, 2022
Time: 14:02:37
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -48.4724
Nobs: 592.000 HQIC: -48.8792
Log likelihood: 7074.98 FPE: 4.56350e-22
AIC: -49.1388 Det(Omega_mle): 3.92487e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.349345 0.067258 5.194 0.000
L1.Burgenland 0.108454 0.040904 2.651 0.008
L1.Kärnten -0.110621 0.021369 -5.177 0.000
L1.Niederösterreich 0.192906 0.085490 2.256 0.024
L1.Oberösterreich 0.123181 0.084340 1.461 0.144
L1.Salzburg 0.257787 0.043366 5.944 0.000
L1.Steiermark 0.036206 0.057212 0.633 0.527
L1.Tirol 0.101572 0.046224 2.197 0.028
L1.Vorarlberg -0.067857 0.040766 -1.665 0.096
L1.Wien 0.016384 0.075050 0.218 0.827
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.052736 0.144676 0.365 0.715
L1.Burgenland -0.037639 0.087988 -0.428 0.669
L1.Kärnten 0.041942 0.045967 0.912 0.362
L1.Niederösterreich -0.204359 0.183894 -1.111 0.266
L1.Oberösterreich 0.456861 0.181421 2.518 0.012
L1.Salzburg 0.282990 0.093283 3.034 0.002
L1.Steiermark 0.113103 0.123067 0.919 0.358
L1.Tirol 0.304884 0.099432 3.066 0.002
L1.Vorarlberg 0.026571 0.087691 0.303 0.762
L1.Wien -0.027981 0.161437 -0.173 0.862
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.197795 0.034354 5.758 0.000
L1.Burgenland 0.089127 0.020893 4.266 0.000
L1.Kärnten -0.007097 0.010915 -0.650 0.516
L1.Niederösterreich 0.241713 0.043666 5.535 0.000
L1.Oberösterreich 0.159519 0.043079 3.703 0.000
L1.Salzburg 0.040127 0.022150 1.812 0.070
L1.Steiermark 0.027268 0.029223 0.933 0.351
L1.Tirol 0.081219 0.023610 3.440 0.001
L1.Vorarlberg 0.054134 0.020823 2.600 0.009
L1.Wien 0.118420 0.038334 3.089 0.002
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.118901 0.034357 3.461 0.001
L1.Burgenland 0.043024 0.020895 2.059 0.039
L1.Kärnten -0.012969 0.010916 -1.188 0.235
L1.Niederösterreich 0.171585 0.043670 3.929 0.000
L1.Oberösterreich 0.335893 0.043083 7.796 0.000
L1.Salzburg 0.100014 0.022152 4.515 0.000
L1.Steiermark 0.111384 0.029225 3.811 0.000
L1.Tirol 0.089417 0.023612 3.787 0.000
L1.Vorarlberg 0.060408 0.020824 2.901 0.004
L1.Wien -0.017898 0.038337 -0.467 0.641
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.126833 0.064549 1.965 0.049
L1.Burgenland -0.044062 0.039257 -1.122 0.262
L1.Kärnten -0.045292 0.020508 -2.208 0.027
L1.Niederösterreich 0.135417 0.082046 1.650 0.099
L1.Oberösterreich 0.159713 0.080943 1.973 0.048
L1.Salzburg 0.285298 0.041619 6.855 0.000
L1.Steiermark 0.058260 0.054908 1.061 0.289
L1.Tirol 0.158018 0.044363 3.562 0.000
L1.Vorarlberg 0.097340 0.039124 2.488 0.013
L1.Wien 0.071628 0.072027 0.994 0.320
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.076872 0.050381 1.526 0.127
L1.Burgenland 0.025857 0.030640 0.844 0.399
L1.Kärnten 0.053335 0.016007 3.332 0.001
L1.Niederösterreich 0.190360 0.064038 2.973 0.003
L1.Oberösterreich 0.330884 0.063177 5.237 0.000
L1.Salzburg 0.034982 0.032484 1.077 0.282
L1.Steiermark 0.008231 0.042856 0.192 0.848
L1.Tirol 0.118583 0.034625 3.425 0.001
L1.Vorarlberg 0.065881 0.030537 2.157 0.031
L1.Wien 0.097129 0.056218 1.728 0.084
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173079 0.060728 2.850 0.004
L1.Burgenland 0.005177 0.036933 0.140 0.889
L1.Kärnten -0.065846 0.019295 -3.413 0.001
L1.Niederösterreich -0.107592 0.077190 -1.394 0.163
L1.Oberösterreich 0.207638 0.076152 2.727 0.006
L1.Salzburg 0.054608 0.039156 1.395 0.163
L1.Steiermark 0.247089 0.051658 4.783 0.000
L1.Tirol 0.500124 0.041737 11.983 0.000
L1.Vorarlberg 0.064230 0.036809 1.745 0.081
L1.Wien -0.075346 0.067764 -1.112 0.266
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.161128 0.067373 2.392 0.017
L1.Burgenland -0.001997 0.040974 -0.049 0.961
L1.Kärnten 0.062943 0.021406 2.940 0.003
L1.Niederösterreich 0.166336 0.085636 1.942 0.052
L1.Oberösterreich -0.056023 0.084484 -0.663 0.507
L1.Salzburg 0.208678 0.043440 4.804 0.000
L1.Steiermark 0.138498 0.057310 2.417 0.016
L1.Tirol 0.055612 0.046303 1.201 0.230
L1.Vorarlberg 0.147031 0.040836 3.601 0.000
L1.Wien 0.121039 0.075178 1.610 0.107
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.390094 0.039623 9.845 0.000
L1.Burgenland -0.003235 0.024097 -0.134 0.893
L1.Kärnten -0.020874 0.012589 -1.658 0.097
L1.Niederösterreich 0.202800 0.050363 4.027 0.000
L1.Oberösterreich 0.228105 0.049686 4.591 0.000
L1.Salzburg 0.037008 0.025548 1.449 0.147
L1.Steiermark -0.015344 0.033705 -0.455 0.649
L1.Tirol 0.089606 0.027231 3.291 0.001
L1.Vorarlberg 0.050857 0.024016 2.118 0.034
L1.Wien 0.043888 0.044213 0.993 0.321
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036708 0.103911 0.167529 0.137974 0.096349 0.080149 0.032104 0.209548
Kärnten 0.036708 1.000000 -0.027455 0.131229 0.048631 0.084724 0.443691 -0.067237 0.089237
Niederösterreich 0.103911 -0.027455 1.000000 0.312331 0.118537 0.272102 0.065271 0.151875 0.290971
Oberösterreich 0.167529 0.131229 0.312331 1.000000 0.212379 0.294766 0.166455 0.136268 0.237595
Salzburg 0.137974 0.048631 0.118537 0.212379 1.000000 0.122434 0.091469 0.104720 0.123534
Steiermark 0.096349 0.084724 0.272102 0.294766 0.122434 1.000000 0.133119 0.106150 0.035267
Tirol 0.080149 0.443691 0.065271 0.166455 0.091469 0.133119 1.000000 0.063179 0.150868
Vorarlberg 0.032104 -0.067237 0.151875 0.136268 0.104720 0.106150 0.063179 1.000000 -0.004563
Wien 0.209548 0.089237 0.290971 0.237595 0.123534 0.035267 0.150868 -0.004563 1.000000